﻿package com.bizmlib.utils.visuallogger
{
	
	
	public class VisualLogger extends Object
	{
		private var items:Array;
		private var __oneSecondStep:Number;
		private var __pane:VisualLoggerPane;
		private var startTime:Date;
		
		
		public function VisualLogger()
		{
			items = new Array();
			oneSecondStep = 10;
		}
		
		
		public function get oneSecondStep():Number
		{
			return __oneSecondStep;
		}
		public function set oneSecondStep(value:Number):void
		{
			__oneSecondStep = value;
			if(pane)
			{
				pane.oneSecondStep = oneSecondStep;
			}
		}
		
		public function get pane():VisualLoggerPane
		{
			return __pane;
		}
		public function set pane(value:VisualLoggerPane):void
		{
			__pane = value;
			updatePane();
		}
		
		
		public function start():void
		{
			startTime = new Date();
		}
		public function addEntry(entry:*):void
		{
			if(!entry)
			{
				return;
			}
			var visualLoggerEntry:VisualLoggerEntry = entry as VisualLoggerEntry;
			if(!visualLoggerEntry)
			{
				visualLoggerEntry = new VisualLoggerEntry(entry.value, entry.color);
			}
			
			var currentTime:Date = new Date();
			visualLoggerEntry.milliseconds = currentTime.time - startTime.time;
			items.push(visualLoggerEntry);
			drawEntry(visualLoggerEntry);
		}
		
		
		private function drawEntry(entry:VisualLoggerEntry):void
		{
			pane.drawEntry(entry);
		}
		private function updatePane():void
		{
			if(pane)
			{
				pane.oneSecondStep = oneSecondStep;
			}
			
			//...
		}
	}
}